home *** CD-ROM | disk | FTP | other *** search
- "Chess for C++, v1.2"
- by Walter Karas (Cary, NC)
-
- [ABSTRACT]
-
- The following article presents highlights of "Chess for C++" which is
- immediately avialable on CUG volume #432A. This chess program allows
- zero, one, or two computer opponents to play along the game. This
- documentation is based entirely on that provided by Walter Karas for CUG
- Library.
-
- [PROGRAM USAGE]
-
- CHESS white-player black-player
-
- A player (white or black) is specified as one of "U", "C1", "C2" or
- "C3". "U" specifies that the player's moves will be selected by the
- user. "C1", "C2" or "C3" specifies that the player's moves will be
- selected by the computer. The digit (1, 2 or 3) gives the relative
- skill level with which the computer selects the player's moves. For
- example, the command:
-
- CHESS C2 U
-
- starts a game with the computer selecting the white player's moves (at
- skill level 2) and the user selecting the black player's moves. The
- default for black-player is C2, and the default for white-player is U.
- It is legal for both players to be user-controlled, or for both players
- to be computer-controlled. When playing at skill level 3, the computer
- will take several minutes to select each move.
-
- Pieces on the chess board are represented by two letter strings. The
- first letter is W (for a white piece) or B (for a black piece). Here
- is the legend for the second letter:
-
- P - Pawn
- R - Rook
- N - Knight
- B - Bishop
- Q - Queen
- K - King
-
- [IMPLEMENTATION]
-
- The following files contain the source code for the program:
-
- brdsize.hpp
- charui.cpp
- charui.hpp
- chcharui.cpp
- chcharui.hpp
- chess.cpp
- chess.hpp
- chessui.cpp
- chessui.hpp
- cplayer.cpp
- cplayer.hpp
- main.cpp
- misc.hpp
- player.hpp
- uplayer.cpp
- uplayer.hpp
-
- Here are the important class hierarchies:
-
- PIECE
- *
- *
- ************************************
- * * * * * *
- * * * * * *
- KING QUEEN BISHOP KNIGHT ROOK PAWN
-
-
- PLAYER
- *
- **************
- * *
- * *
- COMPUTERPLAYER USERPLAYER
-
-
- CHARUSERIFACE
- *
- *
- CHESSCHARUSERIFACE
- *
- *
- CHESSUSERIFACE
-
-
- This program uses BIOS calls to interface with the screen and
- keyboard. It could be ported to another character-oriented API by
- changing the implementation of CHARUSERIFACE. It could be ported to a
- GUI API by changing the implementation of CHESSUSERIFACE.
-
- [ALGORITHM FOR COMPUTER PLAYER]
-
- The algorithm for the computer player appears in the play() member
- function of COMPUTERPLAYER as shown below:
-
- GAMESTATUS COMPUTERPLAYER::play(BOARD &board) const
- {
- BOARDMETRIC metric;
- BESTMOVES bestMoves;
- int best;
-
- ChessUI.thinkingMessage(whatColor());
- board.findBestMoves(lookAhead, whatColor(), metric, &bestMoves);
- if (metric.kingSituation[whatColor()] != KINGOK)
- {
- // see if checkmate/stalemate current or predicted
- if (lookAhead > 2)
- board.findBestMoves(2, whatColor(), metric, &bestMoves);
-
- if (metric.kingSituation[whatColor()] == KINGLOST)
- {
- ChessUI.clearMessage();
- ChessUI.mated(whatColor());
- return(GAMEOVER);
- }
- else if (metric.kingSituation[whatColor()] == STALEMATE)
- {
- ChessUI.clearMessage();
- ChessUI.staleMated(whatColor());
- return(GAMEOVER);
- }
- }
-
- best = bestDevelopMove(board, whatColor(), bestMoves);
-
- if (!ChessUI.computerMove(board, whatColor(),
- bestMoves.move[best]))
- return(GAMEOVER);
-
- return(GAMECONTINUE);
- }
-
-
- The first step is to find the list of possible moves which are predicted
- to get the opponent in checkmate, or provide the most material gain (or
- minimize material loss). This prediction is done by looking ahead
- several moves. The number of moves of look-ahead is 2 for skill level
- 1, 3 for skill level 2, and 4 for skill level 3. The look-ahead is
- performed by the recursive findBestMove() member function of the BOARD
- class. To select among the list of best moves, a "coverage/threat"
- metric is used. This metric measures how much of the board will be
- "attackable" after the move, giving extra points for blocking moves by
- the opponent's king. It also encourages moving pieces closer to the
- opponent king.
-
- Please send all comments and bug reports to:
-
- Walt Karas
- 118 Barcelona Ct.
- Cary, NC 27513
-
- This program is no Deep Thought, and can easily be beaten by a good
- human player.
-
- [VERSION INFORMATION]
-
- Version 1.0
- o Initial release.
-
- Version 1.1
- o Removal of obscure bug in Computer Player play() member function.
- o Fine tuning of best development metric.
- o Removal of useless "usage" printing code.
- o Removal of bug with en passant move logic which caused pawns to
- "disappear" from internal representation of board, although they
- were still on the screen.
-
- Version 1.2
- o Small changes, essentially cosmetic in nature.